package com.application.outdoor.pojo;



import java.util.ArrayList;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import ReadWriteXML.XMLBuilder;
import android.R.integer;

public class FileSharePOJO {
	private int id;
	private String tenFile;
	private String nguoiUp;
	private int idNhom;
	private long thoiGian;
	private String path;
	private String ghiChu;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getTenFile() {
		return tenFile;
	}
	public void setTenFile(String tenFile) {
		this.tenFile = tenFile;
	}
	public String getNguoiUp() {
		return nguoiUp;
	}
	public void setNguoiUp(String nguoiUp) {
		this.nguoiUp = nguoiUp;
	}
	public int getIdNhom() {
		return idNhom;
	}
	public void setIdNhom(int idNhom) {
		this.idNhom = idNhom;
	}
	public long getThoiGian() {
		return thoiGian;
	}
	public void setThoiGian(long thoiGian) {
		this.thoiGian = thoiGian;
	}
	
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public String getGhiChu() {
		return ghiChu;
	}
	public void setGhiChu(String ghiChu) {
		this.ghiChu = ghiChu;
	}
	public Element createXMLElement(Document doc){
		Element e=doc.createElement("File");
		e.setAttribute("ID", id+"");
		e.setAttribute("TenFile", tenFile);
		e.setAttribute("NguoiUp", nguoiUp);
		e.setAttribute("IDNhom", idNhom+"");
		e.setAttribute("ThoiGian", thoiGian+"");
		e.setAttribute("Path", path);
		e.setAttribute("GhiChu", ghiChu);
		return e;
	}
	public void parse(Element e){
		this.id=Integer.parseInt(e.getAttribute("ID"));
		this.tenFile=e.getAttribute("TenFile");
		this.nguoiUp=e.getAttribute("NguoiUp");
		this.idNhom=Integer.parseInt(e.getAttribute("IDNhom"));
		this.thoiGian=Long.parseLong(e.getAttribute("ThoiGian"));
		this.path=e.getAttribute("Path");
		this.ghiChu=e.getAttribute("GhiChu");
		
	}
	public static ArrayList<FileSharePOJO> parseList(String xml){
		ArrayList<FileSharePOJO> rs=new ArrayList<FileSharePOJO>();
		try {
			Document doc=XMLBuilder.loadXMLFromString(xml);
			NodeList lstNode=doc.getElementsByTagName("File");
			for(int i=0;i<lstNode.getLength();i++){
				Element e=(Element)lstNode.item(i);
				FileSharePOJO fs=new FileSharePOJO();
				fs.parse(e);
				rs.add(fs);
			}
		} catch (Exception e) {
			rs=null;
		}		
		return rs;
	}
	
	
}
